//  ========== 
//  = 我的资金明细 业务JS = 
//  ==========
var page = 1;
var limit = 8;
var transferType = "";
var Main = function(){
	var _this = this;
	mui('#refreshContainer').pullToRefresh({
				down: {
					callback: function() {
					   var self = this;
						_this.loadData(1,function(){
							self.endPullDownToRefresh();
						});
					}
				},
				up: {
					callback: function() {
						var self = this;
						_this.loadData(page++,function(){
							self.endPullUpToRefresh();
						});
	
					}
				}
			})
	
	this.init();
	this.loadData(page);
};

Main.prototype = {
	init : function(){
		mui('.mui-scroll-wrapper').scroll({
					indicators: true //是否显示滚动条
		});
		var _this = this;
					
		_this.eventInit()
		
	},
	eventInit : function(){//绑定事件
		var _this = this;
        //交易类型查询
			$('#popover li').on('tap',function(){
				transferType = this.getAttribute('data-value');
				//关闭弹出层
				mui('#popover').popover('hide');
                _this.loadData(1); 				      
		    }
		   );
		   mui("#popover").on('tap','li',function(){
		   	 var name = $(this).html();
		   	 var icon = "";
		   	 if(this.getAttribute('data-value') == ''){
		   	 	name="交易类型";
		   	 }else{
		   	 	icon = '<i class="u-iconfont" style="float:right">&#xe627;</i>';
		   	 }
		   	 $('#cond-transfer-type').html(name+'<i class="mui-icon u-iconfont mui-right">&#xe689;</i>');
		   	 
		   	 //移除对号
		   	 $("#popover li").find('i').remove();
		   	 
		   	 $(this).html(name+icon);
		   	 
		   })

	},
	_itemBindTap : function(){//列表绑定点击事件
		
	},
   
	//内容列表
	loadData : function(page,_callback){
		//Util.loading();
		var _this = this;
		var param = {
				isMobile:1,
				memberId:Util.getLoginUser().memberId,
				page:page,
				limit:limit,
				transferType:transferType
				};
	    
		var url = server_url+'/financePurchase/detailFinancePurchase.do';
		$.getJSON(url,param  ,function(data){
			var _html = '';
			if(data.success){
	           for(var i=0;i<data.result.length;i++){
	            	var item = data.result[i];
	            	var date = new Date(item.orderDate);
					_html +='\n <div class="bankroll-article mui-clearfix">';
					_html +='\n 	<div class="lt-box time">   ';
					_html += Util.time.formatDate(date,'hh:mm:ss');
					_html +='\n 	</div>';
					_html +='\n 	<div class="rt-box">';
					_html +='\n 			<div class="rt-box-group">';
					_html +='\n 				<div class="row time-month">';
					_html +=Util.time.formatDate(date,'MM月');
					_html +='\n 				</div>';
					_html +='\n 				<div class="row time-all">';
					_html +='\n 					<i class="mui-icon u-iconfont">&#xe76f;</i>';
					_html += Util.time.formatDate(date,'yyyy-MM-dd');
					_html +='\n 				</div>';
					_html +='\n 				<div class="row tab-row">';
					_html +='\n 					<div class="tab-cell">';
					if(item.incomMoney && item.incomMoney>0){
						_html += '+'+item.incomMoney;
					}
					if(item.payMoney && item.payMoney>0){
						_html += '-'+item.payMoney;
					}					
					_html +='\n 					</div>';
					_html +='\n 					<div class="tab-cell">';
					_html +=item.transferTypeName;
					_html +='\n 					</div>';
					_html +='\n 					<div class="tab-cell">';
					_html +=item.msg;
					_html +='\n 					</div>';
					_html +='\n 				</div>';
					_html +='\n 			';	
					_html +='\n 			</div>';
					_html +='\n 	</div>';
					_html +='\n </div>';
					}	
            	
            }
            //Util.closeLoading();
            if(page == 1){
            	$('.m-fund-list').html('');
            }
			_this._itemBindTap();
             $('.m-fund-list').append(_html);
             
             if($.isFunction(_callback)){
             	_callback();
             }
		});
	}
	
}
